<?php


namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Config;


class ConfigController extends Controller
{
    /**
     * @api {post} api/config/save 创建
     */
    public function save(Request $request) {
        $params = $request->input();
        $model = Config::where('key', $params['key'])->first();
        if (!$model) {
            $model = new Config();
            $model->key = $params['key'];
        }
        $model->params = $params['params'];
        if (isset($params['type'])) {
            $model->type = $params['type'];
        }
        if (isset($params['name'])) {
            $model->name = $params['name'];
        }
        return $model->save();
    }

    /**
     * @api {get} api/config/get 信息
     */
    public function getInfo(Request $request) {
        $params = $request->input();
        $config = Config::where('key', $params['key'])->first();
        return $config;
    }
}
